<?php
class accsess_analiz
{
  var $login = '';
  var $password = '';
		var $result = '';
		var $session_result = '';
		var $id_restaurant = '';
		var $rand_password = '';

  function accsess_analiz()
  {
    include('../../data/data.php');
    if ( isset($_REQUEST['login']) )
    {
   		$this -> login = $_REQUEST['login'];
   	}
    
   	if ( isset($_REQUEST['password']) )
   	{
   		$this -> password = $_REQUEST['password'];
   	}
   	$this -> run();
  }
		
		function generatePassword($length = 8)
		{
    $chars = 'abdefhiknrstyzABDEFGHKNQRSTYZ23456789';
    $numChars = strlen($chars);
    $this -> rand_password = '';
    for ($i = 0; $i < $length; $i++)
    {
      $this -> rand_password .= substr($chars, rand(1, $numChars) - 1, 1);
    }
  }
		
		function create_session()
		{
		  $sql = 'INSERT INTO session (`id`, `id_session`, `id_restoran`, `date`, `time`) VALUES (NULL, \''.$this -> rand_password.'\', \''.$this -> id_restaurant.'\', \'2013-11-13\', \'13:15\')';
		  $this -> session_result = mysql_query($sql) or die("нет вставки");
   	print($this -> rand_password);
		}
		
		function run()
		{
		  $sql = 'SELECT * FROM restaurant WHERE login = \''.$this -> login.'\' and password = \''.$this -> password.'\'';
   	$this -> result = mysql_query($sql) or die("zxcv");
   	if ( mysql_num_rows($this -> result) > 0 )
   	{
   	  $this -> id_restaurant = mysql_result($this -> result,0,'id');
      $this -> generatePassword();
      $this -> create_session();
   	}
		}
}

$obj = new accsess_analiz();
?>